package com.dd.stack.redis.repository;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dd.stack.redis.mapper.DataObjectMapper;
import com.dd.stack.redis.pojo.DO.DataObjectDO;
import com.dd.stack.redis.service.cache.DataObjectCacheService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/6/2 17:38
 * @Description 类功能作用说明
 */
@Repository
@RequiredArgsConstructor
public class DataObjectRepository {

    private final DataObjectMapper dataObjectMapper;

    public DataObjectDO getById(Long id) {
        return dataObjectMapper.selectById(id);
    }

    public List<DataObjectDO> all() {
        return dataObjectMapper.selectList(null);
    }

    public void add(DataObjectDO dataObjectDO) {
        dataObjectMapper.insert(dataObjectDO);
    }

    public void update(DataObjectDO dataObjectDO) {
        LambdaUpdateWrapper<DataObjectDO> luw = new LambdaUpdateWrapper<>();
        luw.eq(DataObjectDO::getId, dataObjectDO.getId());
        dataObjectMapper.update(dataObjectDO, luw);
    }

    public void delete(Long id) {
        dataObjectMapper.deleteById(id);
    }
}
